package com.ktkq.service.teacher.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ktkq.dao.teacher.TeacherMapper;
import com.ktkq.service.teacher.TeacherService;
import com.ktkq.util.PageFinder;
import com.ktkq.util.Pageing;
import com.ktkq.util.TimeUtil;
import com.ktkq.util.font.UploadExcel;
import com.ktkq.vo.Teacher;


@Service("teacherService")
@Transactional
public class TeacherServiceImpl implements TeacherService{

	@Autowired
	TeacherMapper teacherMapper;
	
	@Override
	public PageFinder<Teacher> queryList(Pageing pageing) {
		
		PageFinder<Teacher> pageFinder = new PageFinder<Teacher>();
		
		pageFinder.setRowCount(teacherMapper.pageCount(pageing));
		pageFinder.setDataList(teacherMapper.queryList(pageing));
		
		return pageFinder;
	}

	@Override
	public void insert(Teacher t) {
		
		teacherMapper.insert(t);
	}

	@Override
	public void update(Teacher t) {
		
		teacherMapper.update(t);
	}

	@Override
	public void delete(Teacher t) {
		
		teacherMapper.delete(t);
	}

	@Override
	public List<Teacher> queryListById(int id) {
		
		return teacherMapper.queryById(id);
	}

	@Override
	public List<Teacher>  UploadExcel(String filePath,Teacher t) {
		
		List<Teacher>  lss = new ArrayList<Teacher>();
	List<List<String>> list = new UploadExcel(filePath).AnalysisExcel();

	 if(list.size()!=0){
		 String time = new TimeUtil().getTime();
		 for(List<String> ls :list){
			 Teacher teacher = new Teacher();			
			 teacher.setTeachName(ls.get(1));
			 teacher.setEducation(ls.get(2));
			 teacher.setPosition(ls.get(3));
		     teacher.setAcademy(t.getAcademy());
		     teacher.setPassword("123456");
		     teacher.setRole("01");
		     teacher.setTime(time);
				 lss.add(teacher);
			 teacherMapper.insert(teacher); 
		 } 
		
	 }
	
	return lss;
	}
	
}
